home *** CD-ROM | disk | FTP | other *** search
- Submitted-by: gwc@root.co.uk (Geoff Clare)
-
- In <212aaeINNl49@rodan.UU.NET> ddm26@cas.org (De Mickey) writes:
- >However, the function return value can look valid (e.g.
- >zero), so the application must set errno to zero before the
- >call, and then test errno afterwards, if it wants to be sure
- >the conversion was successful.
-
- > errno = 0;
- > dbl = strtod(ptr, &endptr);
- > if (errno != 0) {
- > /* complain to someone */
- > }
-
- Although this example is probably safe, in general you should only ever
- examine errno if the function return value indicates that it safe to
- do so. This is because POSIX allows functions to set errno to a non-zero
- value when they succeed (the classic example is errno being set to ENOTTY
- by stdio functions).
-
- So in the case of pathconf(), which started this thread, instead of
-
- errno = 0;
- longval = pathconf(file, _PC_WHATEVER);
- if (errno != 0) {
- /* complain to someone */
- }
-
- you should use
-
- errno = 0;
- longval = pathconf(file, _PC_WHATEVER);
- if (longval == -1 && errno != 0) {
- /* complain to someone */
- }
-
- --
- Geoff Clare <gwc@root.co.uk> (USA antiquated mailers: ...!uunet!root.co.uk!gwc)
- UniSoft Limited, London, England. Tel: +44 71 729 3773 Fax: +44 71 729 3273
-
-
- Volume-Number: Volume 31, Number 100
-
-